<?php
include_once(dirname(__FILE__) . "/comment-service-adapter.php");

$article_id = intval($_GET['aid']);
$offset = intval($_GET['s']);
$count = intval($_GET['n']);
$total_pages = intval($_GET['t']);

$service_adapter = new CommentServiceAdapter();
$comments_result = $service_adapter->GetArticleComments($article_id, $offset, $count);

// print_r($comments_result);
if ($comments_result && $comments_result->success) {
  echo '{code:0, comments:[';
  $cur_count = 0;
  foreach($comments_result->comments as $comment) {
    if ($cur_count++ > 0) {
      echo ',';
    }
    echo '{';
    echo '"sender_id" : ' . $comment->sender_id . ',';
    echo '"sender_name" : ' . json_encode($comment->sender_name) . ',';
    echo '"time_stamp" : ' . $comment->time_stamp . ',';
    echo '"content" : ' . json_encode(htmlspecialchars($comment->content));
    echo '}';
  }
  echo '], nav_html:';
  echo json_encode(CommonPageNav2($total_pages, $count, $offset / $count + 1, 2, "#comment%d"));
  echo '}';
} else {
  echo '{code:-1}';
}
?>
